# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Corrado Primier <bardo@aur.archlinux.org>

pkgname=rtkit
pkgver=0.11+8+ge0a51fe
pkgrel=1
pkgdesc="Realtime Policy and Watchdog Daemon"
arch=(x86_64)
url="https://github.com/heftig/rtkit"
license=(GPL3 'custom:BSD')
depends=(dbus polkit systemd)
makedepends=(git)
_commit=e0a51fe262ff7167622a8e58f876a663b9471124  # master
source=("git+https://github.com/heftig/rtkit#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd $pkgname
  ./autogen.sh
}

build() {
  cd $pkgname
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib \
    --with-systemdsystemunitdir=/usr/lib/systemd/system
  make

  ./rtkit-daemon --introspect > org.freedesktop.RealtimeKit1.xml
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install

  install -Dt "$pkgdir/usr/share/dbus-1/interfaces" -m644 org.freedesktop.RealtimeKit1.xml

  echo 'u rtkit 133 "RealtimeKit" /proc' |
    install -Dm644 /dev/stdin "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"

  sed -ne '4,25p' rtkit.c |
    install -Dm644 /dev/stdin "$pkgdir/usr/share/licenses/$pkgname/COPYING"
  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 LICENSE
}
